package basics.passByValue;

import com.google.common.collect.Lists;
import org.junit.Test;

import javax.swing.plaf.SpinnerUI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Test02 {

    private List<Integer> baseList = Lists.newArrayList(1,2,3);

    public void swap(List list){
        //拷贝的地址变了,所以不影响原baseList
        list = new ArrayList();
        list.add(2);
        list.add(1);
        System.out.println(list);
        System.out.println(baseList);
    }

    @Test
    public void test01(){
        swap(baseList);
    }
    @Test
    public void test02(){
        swap2(baseList);
    }
    //此时,baseList是会变的, 虽然list是baseList的一个引用拷贝,但是他们指向对重的地址一样,添加值,堆也会改变
    public void swap2(List list){
        list.add(2);
        list.add(1);
        System.out.println(list);
        System.out.println(baseList);
    }
}
